<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图纸ID" prop="drawingId">
        <el-input
          v-model="queryParams.drawingId"
          placeholder="请输入图纸ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接触网开关器ID" prop="catenarySwitchId">
        <el-input
          v-model="queryParams.catenarySwitchId"
          placeholder="请输入接触网开关器ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入线名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线code" prop="lineCode">
        <el-input
          v-model="queryParams.lineCode"
          placeholder="请输入线code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线类型" prop="lineType">
        <el-select v-model="queryParams.lineType" placeholder="请选择线类型" clearable>
          <el-option
            v-for="dict in dict.type.biz_line_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否可放置火车" prop="isTrainPlaceable">
        <el-select v-model="queryParams.isTrainPlaceable" placeholder="请选择是否可放置火车" clearable>
          <el-option
            v-for="dict in dict.type.biz_t_f"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:single_line_annotation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:single_line_annotation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:single_line_annotation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:single_line_annotation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="single_line_annotationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="部门id" align="center" prop="deptId" />
      <el-table-column label="图纸ID" align="center" prop="drawingId" />
      <el-table-column label="接触网开关器ID" align="center" prop="catenarySwitchId" />
      <el-table-column label="线名称" align="center" prop="lineName" />
      <el-table-column label="线code" align="center" prop="lineCode" />
      <el-table-column label="x1" align="center" prop="x1" />
      <el-table-column label="y1" align="center" prop="y1" />
      <el-table-column label="x2" align="center" prop="x2" />
      <el-table-column label="y2" align="center" prop="y2" />
      <el-table-column label="线类型" align="center" prop="lineType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.biz_line_type" :value="scope.row.lineType"/>
        </template>
      </el-table-column>
      <el-table-column label="是否可放置火车" align="center" prop="isTrainPlaceable">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.biz_t_f" :value="scope.row.isTrainPlaceable"/>
        </template>
      </el-table-column>
      <el-table-column label="标准参数" align="center" prop="standardParams" />
      <el-table-column label="自定义参数" align="center" prop="customParams" />
      <el-table-column label="扩展信息" align="center" prop="ext" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:single_line_annotation:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:single_line_annotation:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改单条直线标注对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="图纸ID" prop="drawingId">
          <el-input v-model="form.drawingId" placeholder="请输入图纸ID" />
        </el-form-item>
        <el-form-item label="接触网开关器ID" prop="catenarySwitchId">
          <el-input v-model="form.catenarySwitchId" placeholder="请输入接触网开关器ID" />
        </el-form-item>
        <el-form-item label="线名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入线名称" />
        </el-form-item>
        <el-form-item label="线code" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入线code" />
        </el-form-item>
        <el-form-item label="x1" prop="x1">
          <el-input v-model="form.x1" placeholder="请输入x1" />
        </el-form-item>
        <el-form-item label="y1" prop="y1">
          <el-input v-model="form.y1" placeholder="请输入y1" />
        </el-form-item>
        <el-form-item label="x2" prop="x2">
          <el-input v-model="form.x2" placeholder="请输入x2" />
        </el-form-item>
        <el-form-item label="y2" prop="y2">
          <el-input v-model="form.y2" placeholder="请输入y2" />
        </el-form-item>
        <el-form-item label="线类型" prop="lineType">
          <el-select v-model="form.lineType" placeholder="请选择线类型">
            <el-option
              v-for="dict in dict.type.biz_line_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否可放置火车" prop="isTrainPlaceable">
          <el-radio-group v-model="form.isTrainPlaceable">
            <el-radio
              v-for="dict in dict.type.biz_t_f"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="标准参数" prop="standardParams">
          <el-input v-model="form.standardParams" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="自定义参数" prop="customParams">
          <el-input v-model="form.customParams" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展信息" prop="ext">
          <el-input v-model="form.ext" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSingle_line_annotation, getSingle_line_annotation, delSingle_line_annotation, addSingle_line_annotation, updateSingle_line_annotation } from "@/api/system/single_line_annotation"

export default {
  name: "Single_line_annotation",
  dicts: ['biz_line_type', 'biz_t_f'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 单条直线标注表格数据
      single_line_annotationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        drawingId: null,
        catenarySwitchId: null,
        lineName: null,
        lineCode: null,
        lineType: null,
        isTrainPlaceable: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateBy: [
          { required: true, message: "更新者不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" }
        ],
        drawingId: [
          { required: true, message: "图纸ID不能为空", trigger: "blur" }
        ],
        catenarySwitchId: [
          { required: true, message: "接触网开关器ID不能为空", trigger: "blur" }
        ],
        lineName: [
          { required: true, message: "线名称不能为空", trigger: "blur" }
        ],
        lineCode: [
          { required: true, message: "线code不能为空", trigger: "blur" }
        ],
        x1: [
          { required: true, message: "x1不能为空", trigger: "blur" }
        ],
        y1: [
          { required: true, message: "y1不能为空", trigger: "blur" }
        ],
        x2: [
          { required: true, message: "x2不能为空", trigger: "blur" }
        ],
        y2: [
          { required: true, message: "y2不能为空", trigger: "blur" }
        ],
        lineType: [
          { required: true, message: "线类型不能为空", trigger: "change" }
        ],
        isTrainPlaceable: [
          { required: true, message: "是否可放置火车不能为空", trigger: "change" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询单条直线标注列表 */
    getList() {
      this.loading = true
      listSingle_line_annotation(this.queryParams).then(response => {
        this.single_line_annotationList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deptId: null,
        drawingId: null,
        catenarySwitchId: null,
        lineName: null,
        lineCode: null,
        x1: null,
        y1: null,
        x2: null,
        y2: null,
        lineType: null,
        isTrainPlaceable: null,
        standardParams: null,
        customParams: null,
        ext: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加单条直线标注"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getSingle_line_annotation(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改单条直线标注"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSingle_line_annotation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addSingle_line_annotation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除单条直线标注编号为"' + ids + '"的数据项？').then(function() {
        return delSingle_line_annotation(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/single_line_annotation/export', {
        ...this.queryParams
      }, `single_line_annotation_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
